package com.weasing.res.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.weasing.res.dao.IWxUserlistDao;
import com.weasing.res.dao.base.impl.BaseDaoImpl;
import com.weasing.res.domain.WxUserlist;

@Repository
public class WxUserlistDaoImpl extends BaseDaoImpl<WxUserlist> implements
		IWxUserlistDao {

	@Override
	public List<WxUserlist> findWxUserlistByCondition(String truename,
			String idcardno) {
		String hql = "from WxUserlist where 1=1";
		if (truename != null && !"".equals(truename)) {
			hql += " and truename like '%" + truename + "%'";
		}
		if (idcardno != null && !"".equals(idcardno)) {
			hql += " and idcardno like '%" + idcardno + "%'";
		}
		List<WxUserlist> wxUserlist = (List<WxUserlist>) this
				.getHibernateTemplate().find(hql);
		return wxUserlist;
	}

	@Override
	public Integer ageCount(Integer begin, Integer end) {
		String hql = "select count(*) from WxUserlist u where u.age >= "
				+ begin + " and u.age <= " + end;
		Session session = this.getSessionFactory().getCurrentSession();
		Query query = session.createQuery(hql);
		Integer i = ((Long) query.iterate().next()).intValue();
		return i;
	}

}
